package cn.edu.nju.setting;

import java.util.List;

import com.devsmart.android.HorizontalListView;

import cn.edu.nju.R;

import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TagCategoryListAdapter extends BaseAdapter{
	private Activity context;
	private TagProvider provider;
	private LayoutInflater inflater;
	private List<String> tagCategories;
	private ViewGroup parent;
	private int currentSelected;
	
	public TagCategoryListAdapter(Activity activity, ViewGroup parent){
		this.context = activity;
		this.provider = TagProvider.getInstance(activity);
		this.inflater = context.getLayoutInflater();
		this.tagCategories = provider.getTagCategories();
		
		this.parent = parent;
	}
	
	public int getCount(){
		return tagCategories.size();
	}
	
	public String getItem(int position){
		return tagCategories.get(position);
	}
	
	public long getItemId(int position){
		return position;
	}
	
	public View getView(int position, View convertView, ViewGroup parent){
		View result;
		TextView categoryText;
		String categoryContent = getItem(position);
		if(convertView != null){
			result = convertView;
			categoryText = (TextView) result.findViewById(R.id.category_text);
			categoryText.setText(categoryContent);
		}
		else{
			result = inflater.inflate(R.layout.tag_category_list_item, parent, false);
			categoryText =(TextView) result.findViewById(R.id.category_text);
			categoryText.setText(categoryContent);
		}
		if(currentSelected == position){
			categoryText.setBackgroundResource(R.drawable.selected_rounded_rectangle);
			categoryText.setTextColor(R.color.white);
		}
		else{
			categoryText.setBackgroundResource(R.drawable.rounded_rectangle);
			categoryText.setTextColor(R.color.tag_font_color);
		}
		return result;
	}
	
	public void setCurrentSelected(int position){
		this.currentSelected = position;
	}
}
